package com.newtouch.bxzs.database.synchronize.batch.writer;

import com.newtouch.bxzs.database.synchronize.mapper.income.IncomeDetailMapper;
import com.newtouch.bxzs.database.synchronize.mapper.income.IncomeEstimateDetailMapper;
import com.newtouch.bxzs.database.synchronize.mapper.income.IncomeEstimateMapper;
import com.newtouch.bxzs.database.synchronize.mapper.income.IncomeMapper;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeDetailVO;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeEstimateVO;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeVO;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 业绩同步入库
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/8 13:42</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
@SuppressWarnings("unchecked")
public class WriterIncome {

    @Autowired
    private IncomeMapper incomeMapper;

    @Autowired
    private IncomeDetailMapper incomeDetailMapper;

    @Autowired
    private IncomeEstimateMapper incomeEstimateMapper;

    @Autowired
    private IncomeEstimateDetailMapper incomeEstimateDetailMapper;

    /**
     * 同步收入数据至数据库
     * @return ItemWriter
     */
    public ItemWriter<IncomeVO> addIncomeList(){
        return list -> incomeMapper.addIncomeList((List<IncomeVO>) list,new Date());
    }

    /**
     * 同步收入数据明细至数据库
     * @return ItemWriter
     */
    public ItemWriter<IncomeDetailVO> addIncomeDetailList(){
        return list -> incomeDetailMapper.addIncomeDetailList((List<IncomeDetailVO>) list,new Date());
    }

    /**
     * 同步预估收入数据至数据库
     * @return ItemWriter
     */
    public ItemWriter<IncomeEstimateVO> addIncomeEstimateList(){
        return list -> incomeEstimateMapper.addIncomeEstimateList((List<IncomeEstimateVO>) list,new Date());
    }

    /**
     * 同步收入数据明细至数据库
     * @return ItemWriter
     */
    public ItemWriter<IncomeDetailVO> addIncomeEstimateDetailList(){
        return list -> incomeEstimateDetailMapper.addIncomeEstimateDetailList((List<IncomeDetailVO>) list,new Date());
    }
}
